package com.net.orders.controller;

import com.caikun.model.common.Result;
import com.caikun.model.entity.OrderServiceDetail;
import com.caikun.model.vo.OrderServiceDetailVO;
import com.github.pagehelper.Page;
import com.net.orders.service.OrderServiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 订单所选服务表(OrderServiceDetail)表控制层
 *
 * @author makejava
 * @since 2025-07-17 11:12:42
 */
@Slf4j
@RestController
@RequestMapping("/orderService")
public class OrderServiceController {
    /**
     * 服务对象
     */
    @Autowired
    private OrderServiceService orderServiceService;

    /**
     * 分页查询
     *
     * @param orderServiceDetail 筛选条件
     * @param pageNum      当前页码
     * @param pageSize     每页大小
     * @return 查询结果
     */
    @PostMapping("/page")
    public Result<Page<OrderServiceDetail>> queryByPage(@RequestBody OrderServiceDetail orderServiceDetail, int pageNum, int pageSize) {
        return Result.success(this.orderServiceService.queryByPage(orderServiceDetail, pageNum, pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/search/{id}")
    public Result<List<OrderServiceDetailVO>> queryById(@PathVariable("id") Integer id) {

        List<OrderServiceDetailVO> orderServiceDetailVOList = orderServiceService.queryById(id);
        log.info("查询结果：{}", orderServiceDetailVOList);
        return Result.success(orderServiceDetailVOList);
    }

    /**
     * 新增数据
     *
     * @param orderServiceDetail 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public Result<OrderServiceDetail> add(@RequestBody OrderServiceDetail orderServiceDetail) {
        return Result.success(this.orderServiceService.insert(orderServiceDetail));
    }

    /**
     * 编辑数据
     *
     * @param orderServiceDetail 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public Result<OrderServiceDetail> edit(@RequestBody OrderServiceDetail orderServiceDetail) {
        return Result.success(this.orderServiceService.update(orderServiceDetail));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete")
    public Result<Boolean> deleteById(Integer id) {
        return Result.success(this.orderServiceService.deleteById(id));
    }

}

